<?php

Yii::import('application.modules.news.models.News');
Yii::import('application.modules.news.models.NewsCategories');
class SearchController extends Controller {

    /**
     * Lists all models.
     */
    public $layout = '//layouts/column2';

    public function init() {
        Yii::app()->theme = 'home';
    }

    function actionView() {
        $key = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : '';
        $this->pageTitle = 'Tim kiem: ' . $key;
        if (!empty($key)) {
            $criteria = new CDbCriteria();
            $criteria->condition = 'name like "%' . $key . '%"';
            $criteria->order = 'create_time DESC';
            $count = News::model()->count($criteria);
            $pages = new CPagination($count);
            $pages->pageSize = 12;
            $pages->applyLimit($criteria);
            $model = News::model()->findAll($criteria);
            $this->render('view', array('model' => $model, 'pages' => $pages));
        } else {
            throw new CHttpException(400, 'Ban phai nhap tu khoa tim kiem');
        }
    }

}